public class Solution1 {
    //647. 回文子串
    public int countSubstrings(String s) {
        int n = s.length();
        boolean[][] dp = new boolean[n][n];
        int ret = 0;
        for (int j = 0; j < n; j++) {
            for (int i = j; i >= 0; i--) {
                if (s.charAt(i) == s.charAt(j)) {
                    if (i == j) {
                        dp[i][j] = true;
                        ret += 1;
                    } else if (i + 1 == j && s.charAt(i) == s.charAt(j)) {
                        dp[i][j] = true;
                        ret += 1;
                    } else {
                        dp[i][j] = dp[i+1][j-1];
                        if (dp[i][j] == true) {
                            ret += 1;
                        }
                    }
                }

            }
        }
        return ret;

    }
}
